local old_require = require
function require(m_name)
    local APP_ROOT = ngx.var.document_root
    local VANILLA_VERSION_DIR_STR = "0_1_0_rc5"
    local VANILLA_ROOT = "D:/Visual-NMP-x64/Bin/Nginx/lualib/vanilla/framework/"

    local va_m_name = VANILLA_VERSION_DIR_STR .. "/" .. m_name
    local va_name_no_va_m_name = VANILLA_VERSION_DIR_STR .. "/vanilla/" .. m_name
    local app_m_name = APP_ROOT .. "/" .. m_name
    local app_application_m_name = APP_ROOT .. "/application/" .. m_name
    local app_library_m_name = APP_ROOT .. "/application/library/" .. m_name

    if package.loaded[va_m_name] then return package.loaded[va_m_name]
    elseif package.loaded[va_name_no_va_m_name] then return package.loaded[va_name_no_va_m_name]
    elseif package.loaded[app_m_name] then return package.loaded[app_m_name]
    elseif package.loaded[app_application_m_name] then return package.loaded[app_application_m_name]
    elseif package.loaded[app_library_m_name] then return package.loaded[app_library_m_name]
    elseif package.loaded[m_name] then return package.loaded[m_name] end
    --ngx.say(m_name .. "<br />")

    local vanilla_module_name
    local vanilla_framework_path = VANILLA_ROOT .. "/?.lua;" .. VANILLA_ROOT .. "/?/init.lua"
    if package.searchpath(va_m_name, vanilla_framework_path) ~=nil then
        vanilla_module_name = va_m_name
    elseif package.searchpath(va_name_no_va_m_name, vanilla_framework_path) ~=nil then
        vanilla_module_name = va_name_no_va_m_name
    elseif package.searchpath(app_m_name, "?.lua;?/init.lua") ~=nil then
        vanilla_module_name = app_m_name
    elseif package.searchpath(app_application_m_name, "?.lua;?/init.lua") ~=nil then
        vanilla_module_name = app_application_m_name
    elseif package.searchpath(app_library_m_name, "/?.lua;/?/init.lua") ~=nil then
        vanilla_module_name = app_library_m_name
    else
        vanilla_module_name = m_name
    end
    --ngx.say(vanilla_module_name .. "<-------><br />")
    return old_require(vanilla_module_name)
end

if ngx.var.VA_DEV ~= nil then
    local helpers = require "vanilla.v.libs.utils"
    function sprint_r( ... )
        return helpers.sprint_r(...)
    end

    function lprint_r( ... )
        local rs = sprint_r(...)
        print(rs)
    end

    function print_r( ... )
        local rs = sprint_r(...)
        ngx.say(rs)
    end

    function err_log(msg)
        ngx.log(ngx.ERR, "===zjdebug" .. msg .. "===")
    end
end
require("pub.index"):run(ngx)